package edu.fzu.costlog.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtils {

	private static final String CONN_URL = "jdbc:mysql://localhost:3306/study";
	private static final String USERNAME = "root";
	private static final String PASSWORD = "root";
//	private static final String USERNAME = "test1";
//	private static final String PASSWORD = "abc123";
	
	public Connection getConn(){
		
		Connection conn = null;
		
		try {
			
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(CONN_URL,USERNAME,PASSWORD);
		} 
		catch (ClassNotFoundException e) {

			e.printStackTrace();
		} 
		catch (SQLException e) {
			
			e.printStackTrace();
		}
		
		return conn;
	}
	
	
	public void releaseResource(Connection conn, PreparedStatement pstmt, ResultSet rset){
		
		try{
		  
		   if(rset!= null) rset.close();
		   if(pstmt!= null) pstmt.close();
		   if(conn!= null) conn.close();	
		}
		catch(SQLException e){
			
			e.printStackTrace();
		}
	}
}
